import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { PageDto } from "src/common/dto/dto";
import { JumpType, Status } from "src/dictionaries/index.enum";
import { NoticeType } from "../entities/notice.entity";
import { IsNotEmpty, IsEnum, IsDateString } from "class-validator";

export class GetNoticeDto extends PageDto {
    /** 标题 */
    @ApiPropertyOptional({
        type: String,
        name: 'title',
        description: '标题',
    })
    public readonly title: string;
    /** 是否启用 */
    @ApiPropertyOptional({
        name: 'status',
        description: '是否启用',
        enum: Status,
    })
    public readonly status: Status;

    @ApiPropertyOptional({
        type: String,
        name: 'expirationStart',
        description: '有效期开始时间',
    })
    public readonly expirationStart?: string;

    @ApiPropertyOptional({
        type: String,
        name: 'expirationEnd',
        description: '有效期结束时间',
    })
    public readonly expirationEnd?: string;

    /** 跳转类型 */
    @ApiPropertyOptional({
        name: 'jumpType',
        description: '跳转类型',
        enum: JumpType,
    })
    public readonly jumpType: JumpType;

    /** 公告类型 */
    @ApiPropertyOptional({
        name: 'type',
        description: '公告类型',
        enum: NoticeType,
    })
    public readonly type: NoticeType;
}
export class CreateNoticeDto {
    /** 标题 */
    @IsNotEmpty({ message: '标题不能为空' })
    @ApiProperty({
        type: String,
        name: 'title',
        description: '标题',
    })
    public readonly title?: string;
    /** 跳转链接 */
    @ApiPropertyOptional({
        type: String,
        name: 'url',
        description: '跳转链接',
    })
    public readonly url?: string;
    /** 文章ID */
    @ApiPropertyOptional({
        type: Number,
        name: 'articleId',
        description: '文章ID',
    })
    public readonly articleId?: number;
    /** 是否启用 */
    @IsEnum(Status)
    @IsNotEmpty({ message: '状态不能为空' })
    @ApiProperty({
        name: 'status',
        description: '是否启用',
        enum: Status,
    })
    public readonly status: Status;
    /** 内容 */
    @IsNotEmpty({ message: '内容不能为空' })
    @ApiProperty({
        type: String,
        name: 'content',
        description: '内容',
    })
    public readonly content?: string;

    /** 公告类型 */
    @IsEnum(NoticeType)
    @IsNotEmpty({ message: '公告类型不能为空' })
    @ApiProperty({
        name: 'type',
        description: '公告类型',
        enum: NoticeType,
    })
    public readonly type: NoticeType;

    /** 跳转类型 */
    @IsEnum(JumpType)
    @IsNotEmpty({ message: '跳转类型不能为空' })
    @ApiProperty({
        name: 'jumpType',
        description: '跳转类型',
        enum: JumpType,
    })
    public readonly jumpType: JumpType;
    /** 有效期开始时间 */
    @IsDateString({ message: '有效期开始时间格式错误' })
    @IsNotEmpty({ message: '有效期开始时间不能为空' })
    @ApiProperty({
        type: String,
        name: 'expirationStart',
        description: '有效期开始时间',
    })
    public readonly expirationStart?: string;
    /** 有效期结束时间 */
    @IsDateString({ message: '有效期结束时间格式错误' })
    @IsNotEmpty({ message: '有效期结束时间不能为空' })
    @ApiProperty({
        type: String,
        name: 'expirationEnd',
        description: '有效期结束时间',
    })
    public readonly expirationEnd?: string;
}
export class UpdateNoticeDto extends CreateNoticeDto {
    @IsNotEmpty({ message: 'id不能为空' })
    @ApiProperty({
        type: Number,
        name: 'id',
        description: 'id',
    })
    public readonly id: number;
}